/*
package com.adingxiong.cft.fliter;

import com.adingxiong.cft.entity.TUser;
import com.adingxiong.cft.errors.Assert;
import com.adingxiong.cft.service.ILoginLogService;
import com.adingxiong.cft.service.ITUserService;
import com.adingxiong.cft.util.IpUtils;
import com.adingxiong.cft.util.JwtTokenUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

*/
/**
 * @ClassName MyLogoutSuccessHandler
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/9/25 17:43
 **//*

@Slf4j
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {

    String head = "Ading ";

    @Autowired
    private ILoginLogService service;
    @Autowired
    private ITUserService userService;

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
          String ip = IpUtils.getRealIp(httpServletRequest);
          String token = httpServletRequest.getHeader("Authorization");
          if(token == null) {
              Assert.fail("用户未登录");
          }
          JwtTokenUtil jwtTokenUtil = new JwtTokenUtil();

          String username = jwtTokenUtil.getUserNameFromToken(token.substring(head.length()));
          if(username  == null ) {
              Assert.fail("token过期");
          }
          TUser user = userService.getUserByUsername(username);

          boolean update = service.update(user.getId(),new Date());
          if (!update) Assert.fail("更新退出日志失败");
    }
}
*/
